﻿@{
    ViewBag.Title = "文本日志";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="row">
    <div class="col-md-3">
        <div class="box box-primary">
            <div class="box-header with-border">
                <h3 class="box-title">文本日志</h3>
                <div class="box-tools pull-right">
                    <a href="javascript:void(0);" onclick=" loadTree(); return false; " data-toggle="tooltip" title="刷新" class="btn btn-default btn-sm"><i class="fa fa-refresh">刷新</i></a>
                    <a href="javascript:void(0);" onclick=" arrowin(); return false; " data-toggle="tooltip" title="展开" class="btn btn-default btn-sm"><i class="fa fa-folder" id="arrowin">展开</i></a>
                    <a class="btn btn-danger  btn-sm" data-widget="collapse" data-toggle="tooltip" title="伸缩" style="margin-right: 5px;"><i class="fa fa-minus"></i></a>
                </div>
            </div>
            <div class="box-body" id="tree-box-body" style="overflow: auto">
                <ul id="tree" class="ztree"></ul>
            </div>
        </div>
    </div>
    <div class="col-md-9">

        <div class="box box-primary">
            <div class="box-header with-border">
                <h3 class="box-title">日志内容列表</h3>
            </div>
            <div class="box-body" id="logContent"><h3 style="text-align: center">点击左侧文本日志结构树查看日志详细内容</h3></div>
        </div>
    </div>
</div>
<style>
    #logContent {
        overflow: auto;       
    }
</style>
<script>
    $(function () {
        var height = UtilWindowHeightWidth().WinH - 370;
        $("#tree-box-body,#logContent").height(height + 152);
        loadTree();
    });

    var zNodes, treeObj, setting;

    //初始化组织机构
    function initTree() {
        //配置
        setting = {
            view: {
                dblClickExpand: false,
                showLine: true
            },
            data: {
                simpleData: {
                    enable: true
                }
            },
            callback: {
                onClick: onClickTree
            }
        };
    }

    //初始化树结构:同步
    function initTreeData() {
        UtilAjaxPost("/System/Log/GetLogZTree", {}, function (data) {
            zNodes = data;
            treeObj = $.fn.zTree.init($("#tree"), setting, zNodes);
        });
    }

    //树点击触发
    function onClickTree(e, treeId, treeNode) {
        if (treeNode.isParent) {
            treeObj.expandNode(treeNode);
            return;
        }
        UtilAjaxPostWithTypeWait("/System/Log/TxtLogContent", { filePath: treeNode.url }, "html", function (data) {
            $("#logContent").html(data);
        });

    }
 
    //折叠/展开
    var expand = false;

    function arrowin() {
        if (expand) {
            treeObj.expandAll(false);
            expand = false;
            $("#arrowin").html("展开").attr("class", "fa fa-folder");
            $("#arrowin").parent().attr("title", "展开");
        } else {
            treeObj.expandAll(true);
            expand = true;
            $("#arrowin").html("折叠").attr("class", "fa fa-folder-open");
            $("#arrowin").parent().attr("title", "折叠");
        }
    }

    //加载页面数据
    function loadTree() {
        initTree();
        initTreeData();
        $("#main").attr("src", "");
    }
</script>